package cc.mrbird.febs.common.validator;

import com.wuwenze.poi.validator.Validator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author : dtwei
 * @version : 1
 * @date : 2019/9/24 16:22
 */
public class CardIdValidator implements Validator {

    @Override
    public String valid(Object o) {
        String id_18 = "^[1-9][0-9]{5}(18|19|20)[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}([0-9]|(X|x))";
        String id_15 = "^[1-9][0-9]{5}[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{2}[0-9]";
        String id_valid = "(" + id_18 + ")" + "|" + "(" + id_15 + ")";
        Pattern pattern = Pattern.compile(id_valid);
        Matcher matcher = pattern.matcher((String)o);
        if(!matcher.matches()) {
            return "身份证格式错误，请检查身份证信息";
        }
        return null;
    }
}